<?php

/**
 * This is the model class for table "{{meta}}".
 *
 * The followings are the available columns in table '{{meta}}':
 * @property integer $_id
 * @property string $name
 * @property string $fullname
 * @property string $title
 * @property string $description
 * @property string $item_type
 * @property integer $parent_id
 * @property string $owner_type
 * @property integer $owner_id
 * @property string $profile
 * @property string $value_type
 * @property string $value
 * @property integer $create_time
 * @property integer $modify_time
 * @property integer $delete_time
 * @property integer $space_id
 * @property integer $app_id
 * @property integer $user_id
 * @property string $data
 * @property integer $status
 */
class BAMUserMeta extends BAActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{user_meta}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('parent_id, owner_id, create_time, modify_time, delete_time, space_id, app_id, user_id, status', 'numerical', 'integerOnly'=>true),
			array('name, fullname, title, description, item_type, owner_type, value', 'length', 'max'=>255),
			array('value_type', 'length', 'max'=>45),
			array('profile, data', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('_id, name, fullname, title, description, item_type, parent_id, owner_type, owner_id, profile, value_type, value, create_time, modify_time, delete_time, space_id, app_id, user_id, data, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'_id' => 'ID',
			'name' => 'Name',
			'fullname' => 'Fullname',
			'title' => 'Title',
			'description' => 'Description',
			'item_type' => 'Item Type',
			'parent_id' => 'Parent',
			'owner_type' => 'Owner Type',
			'owner_id' => 'Owner',
			'profile' => 'Profile',
			'value_type' => 'Value Type',
			'value' => 'Value',
			'create_time' => 'Create Time',
			'modify_time' => 'Modify Time',
			'delete_time' => 'Delete Time',
			'space_id' => 'Space',
			'app_id' => 'App',
			'user_id' => 'User',
			'data' => 'Data',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('_id',$this->_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('fullname',$this->fullname,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('item_type',$this->item_type,true);
		$criteria->compare('parent_id',$this->parent_id);
		$criteria->compare('owner_type',$this->owner_type,true);
		$criteria->compare('owner_id',$this->owner_id);
		$criteria->compare('profile',$this->profile,true);
		$criteria->compare('value_type',$this->value_type,true);
		$criteria->compare('value',$this->value,true);
		$criteria->compare('create_time',$this->create_time);
		$criteria->compare('modify_time',$this->modify_time);
		$criteria->compare('delete_time',$this->delete_time);
		$criteria->compare('space_id',$this->space_id);
		$criteria->compare('app_id',$this->app_id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('data',$this->data,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * @return CDbConnection the database connection used for this class
	 */
	public function getDbConnection($app = NULL)
	{
		//return Yii::app()->weproductdb;
                return parent::getDbConnection();
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return BAMMeta the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
